package com.ruoyi.pims.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pims.domain.RyAbcResult;
import com.ruoyi.pims.service.IRyAbcResultService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * ABC分类结果Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/pims/result")
public class RyAbcResultController extends BaseController
{
    private String prefix = "pims/result";

    @Autowired
    private IRyAbcResultService ryAbcResultService;

    @RequiresPermissions("pims:result:view")
    @GetMapping()
    public String result()
    {
        return prefix + "/result";
    }

    /**
     * 查询ABC分类结果列表
     */
    @RequiresPermissions("pims:result:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RyAbcResult ryAbcResult)
    {
        startPage();
        List<RyAbcResult> list = ryAbcResultService.selectRyAbcResultList(ryAbcResult);
        return getDataTable(list);
    }

    /**
     * 导出ABC分类结果列表
     */
    @RequiresPermissions("pims:result:export")
    @Log(title = "ABC分类结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RyAbcResult ryAbcResult)
    {
        List<RyAbcResult> list = ryAbcResultService.selectRyAbcResultList(ryAbcResult);
        ExcelUtil<RyAbcResult> util = new ExcelUtil<RyAbcResult>(RyAbcResult.class);
        return util.exportExcel(list, "ABC分类结果数据");
    }

    /**
     * 新增ABC分类结果
     */
    @RequiresPermissions("pims:result:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存ABC分类结果
     */
    @RequiresPermissions("pims:result:add")
    @Log(title = "ABC分类结果", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RyAbcResult ryAbcResult)
    {
        return toAjax(ryAbcResultService.insertRyAbcResult(ryAbcResult));
    }

    /**
     * 修改ABC分类结果
     */
    @RequiresPermissions("pims:result:edit")
    @GetMapping("/edit/{resultId}")
    public String edit(@PathVariable("resultId") Long resultId, ModelMap mmap)
    {
        RyAbcResult ryAbcResult = ryAbcResultService.selectRyAbcResultByResultId(resultId);
        mmap.put("ryAbcResult", ryAbcResult);
        return prefix + "/edit";
    }

    /**
     * 修改保存ABC分类结果
     */
    @RequiresPermissions("pims:result:edit")
    @Log(title = "ABC分类结果", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RyAbcResult ryAbcResult)
    {
        return toAjax(ryAbcResultService.updateRyAbcResult(ryAbcResult));
    }

    /**
     * 删除ABC分类结果
     */
    @RequiresPermissions("pims:result:remove")
    @Log(title = "ABC分类结果", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ryAbcResultService.deleteRyAbcResultByResultIds(ids));
    }
}
